<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		$("#soform").attr("action", lpath + "?pageNo=" + 1);

		$("#soform").submit();
	}
</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<button style="float: right" type="button" onclick="addmsg()" class="btn btn-info">
				<span class="glyphicon glyphicon-plus"></span>
				&nbsp;新增推荐
			</button>
			<form id="soform" method="post">
				<table>
					<tr>
						<td class="w80" style="padding-top: 5px">
							<label for="companyname" class="center-block">公司名称：</label>
						</td>
						<td class="w150 ">
							<input type="text" class="form-control" name="so_companyname" value="${so_companyname!}" id="so_companyname"  data-options="">
						</td>
						<td class="w80" style="padding-top: 5px; padding-left: 10px">
							<label for="brandname" class="center-block">品牌名称：</label>
						</td>
						<td class="w150 ">
							<input type="text" class="form-control" name="so_brandname" value="${so_brandname!}" id="so_brandname"  data-options="">
						</td>
						<td style="padding-left: 10px">
							<div class="input-group">
								<span class="input-group-btn">
									<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
								</span>
							</div>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th width="10%">#</th>
					<th width="25%">公司名称</th>
					<th width="25%">品牌名称</th>
					<th width="15%">是否推荐到首页</th>
					<th width="10%">排序</th>
					<th width="15%">操作</th>
				</tr>
			</thead>
			[#list pagination.list as recommendbrand ]
			<tr>
				<td align="center">${recommendbrand_index + 1}</td>
				<td align="center">${recommendbrand.companyName!}</td>
				<td align="center">${recommendbrand.brandName!}</td>
				<td align="center">[#if recommendbrand.upToIndex??][#if recommendbrand.upToIndex==1]是[#else]否[/#if][/#if]</td>
				<td align="center">
					<input type="text" id="sortnum${recommendbrand.id!}" placeholder="" name="sortnum" required="" value="${recommendbrand.seq!}" onblur="changeSort(${recommendbrand.id!} , ${recommendbrand.seq!-100});" style="width: 45px; text-align: center;" maxlength="4">
				</td>
				<td align="center">
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="edit('${recommendbrand.id}')">编辑</button>
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="del('${recommendbrand.id}')">删除</button>
				</td>
			</tr>
			[/#list]
		</table>

		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>
</body>
</html>
<script type="text/javascript">
	//打开新增窗口
	function addmsg() {
		top.addTempTab("/recommendbrand/v_add.do");
	}

	//打开编辑窗口
	function edit(id) {
		top.addTempTab("/recommendbrand/v_edit.do?so_id="+id);
	}
	//删除
	function del(id) {//弹出警告框判断是否删除
		if (confirm('是否确认删除')) {
			$.ajax({
				url : '/recommendbrand/ajax_del.do',
				type : 'get',
				dataType : 'json',
				data : {
					id : id
				},
				beforeSend : function() {
					art.dialog.tips("删除中...");
				},
				success : function(data) {
					if (data.success) {
						location.reload();
					} else {
						error_msg(data.msg, function() {
							location.reload();
						});
					}
				}
			});
		}
	}
	

	function changeSort(id , oldsort){
		var sort = $("#sortnum"+id).val();
		if(sort == ''){
			$("#sortnum"+id).val(oldsort==-100?'':oldsort);
			return false;
		}
		
		if(!new RegExp("\\d+").test(sort)){
			alert("输入非法");
			$("#sortnum"+id).val(oldsort);
		}
		$.ajax({
			url : '/recommendbrand/changeSort.do',
			type : 'post',
			dataType : 'json',
			beforeSend:function(){
				$("#sortnum"+id).parent().append('<img id="abc"  src="/res/common/images/loadding.gif" style="width: 20px;height: 20px;position:absolute;"  >');
	        },
	        complete:function(){
	            $("#abc").remove();
	        },
			data : {
				id : id ,
				sort : sort
			},
			success : function(data){
				if(data.res){
				}
			}
		});
	}
	

</script>